#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxm = 1e5+10;
int A[maxm], B[maxm];
ll pre[maxm];
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T; cin >> T;
    while (T--){
        ll N, M; cin >> N >> M;
        for (int i = 0; i < M; ++i) {
            cin >> A[i] >> B[i];
        }
        int AA[maxm];
        memcpy(AA, A, sizeof(A));
        sort(A, A+M, greater<>());
        pre[0] = A[0];
        for (int i = 1; i < M; ++i) {
            pre[i] = pre[i-1] + A[i];
        }
        ll ans = 0;
        for (int i = 0; i < M; ++i) {
            ll b = B[i];
            ll p = lower_bound(A, A+M, b, greater<>()) - A;
            ll tmp;
            if(!p) tmp = AA[i] + b*(N-1);
            else{
                p = min(p, N);
                tmp = pre[p-1];
                if(p < N){
                    if(AA[i] > b) tmp+=b*(N-p);
                    else tmp += AA[i] + b*(N-p-1);
                }
            }
            ans = max(ans, tmp);
        }
        cout << ans << "\n";
    }
    return 0;
}